package io.github.annyylxyms.gyncache.command;

import io.github.annyylxyms.gyncache.core.Command;
import io.github.annyylxyms.gyncache.core.GynCache;
import io.github.annyylxyms.gyncache.core.Reply;

/**
 *
 * @author Anny
 * @date 2025/1/15 17:23
 */
public class LrangeCommand implements Command {
    @Override
    public String name() {
        return "LRANGE";
    }

    @Override
    public Reply<?> exec(GynCache cache, String[] args) {
        String key = getKey(args);
        String[] vals = getParamsNoKey(args);
        int start = Integer.parseInt(vals[0]);
        int end = Integer.parseInt(vals[1]);
        return Reply.array(cache.lrange(key, start, end));
    }
}
